package com.daybreak.controller;

import com.alibaba.fastjson.JSONObject;
import com.daybreak.bean.UserInfo;
import com.daybreak.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BusinessController {

    @Autowired
    private UserService userService;

    @RequestMapping("adminCall")
    @ResponseBody
    public String adminCall(){
        System.out.println("Hello");
        return "adminCall~";
    }

    @RequestMapping("user1Call")
    @ResponseBody
    public String user1Call(){
        return "user1Call~";
    }

    @RequestMapping("user2Call")
    @ResponseBody
    public String user2Call(){
        return "user2Call~";
    }

    @RequestMapping("user3Call")
    @ResponseBody
    public String user3Call(){
        return "user3Call~";
    }

    //用户登录后，会把UserDetails对象放入context中，此接口用于测试存放的用户信息
    @RequestMapping("/whoAmI")
    @ResponseBody
    public String whoAmI()
    {
        return JSONObject.toJSONString(SecurityContextHolder.getContext().getAuthentication().getPrincipal());
    }
    @RequestMapping("/index")
    public  String main() {
      return "welcome";
    }
    @RequestMapping("/user/**")
    public  String userRole() {
        System.out.println("Hello");
        return "user";
    }

    @RequestMapping("/user/ha")
    public  String userhh() {
        System.out.println("Hello/Hello");
        return "user";
    }


}
